<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>学院管理</title>
		<include file="Layout:ins_css" />
		<style type="text/css">
			/*#addBtn {
				margin-top: -9px;
			}*/
			
			#addBtn {
				float: right;
				margin: -7px -6px 9px;
			}
			
			.b-search {
				margin-left: 3px;
				float: right;
				padding: 5px 9px;
				background-color: #436EEE;
				border-color: #436EEE;
			}
			
			.price-div {
				float: left;
				margin: 12px 0px 6px 16px;
			}
			
			.price-div input {
				width: 8em;
				float: left;
				margin-right: 6px;
			}
			
			.price-div p {
				line-height: 25px;
				margin-right: 6px;
				float: left;
			}
			
			.price-div select {
				float: left;
				width: 70%;
				margin-right: 10px;
			}
			
			#langueType {
				height: 32px;
			}
			
			.select2-drop {
				z-index: 10050 !important;
			}
			
			.select2-search-choice-close {
				margin-top: 0 !important;
				right: 2px !important;
				min-height: 10px;
			}
			
			.select2-search-choice-close:before {
				color: black !important;
			}
			/*防止select2不会自动失去焦点*/
			
			.select2-container {
				z-index: 16000 !important;
			}
			
			.select2-drop-mask {
				z-index: 15990 !important;
			}
			
			.select2-drop-active {
				z-index: 15995 !important;
			}
			
			.staff {
				margin-top: 6px;
			}
			
			.nationality {
				margin-right: 15px;
			}
		</style>
	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>学院管理</h5>
							<button id="addBtn" class="btn btn-info pull-right">新增</button>
						</div>
						<div class="ibox-content">
							<table class="table table-striped table-bordered table-hover dataTables-example" style="width:100%;">
								<thead>
									<tr>
										<!--<th width="" class="hidden">排序</th>-->
										<th width="20%">学院编号</th>
										<th width="20%">学院名称 </th>
										<th width="20%">办公地点</th>
										<th width="20%">院长</th>
										<th width="20%">操作</th>
									</tr>
								</thead>
								<tbody></tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- Modal 新增学院-->
		<div class="modal fade" id="AdCollegeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">新增学院</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="form_add">
							<div class="form-group">
								<label class="col-sm-3 control-label">学院编号</label>
								<div class="col-sm-7">
									<input type="text" id="add_sch_id" name="add_sch_id" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学院名称</label>
								<div class="col-sm-7">
									<input type="text" id="add_sch_name" name="add_sch_name" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">办公地点</label>
								<div class="col-sm-7">
									<input type="text" id="add_sch_office" name="add_sch_office" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">院长</label>
								<select class="form-control poiu" id="add_tea_boss" name="add_tea_boss">
									<option value="0">请选择</option>
									<volist name="tea_sel_add" id="vo">
										<option value="{$vo.tea_id}">{$vo.tea_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3  control-label " style="margin-top: 30px;">简介: </label>
								<div class="col-sm-7">
									<textarea name="add_sch_intro" id="add_sch_intro" class="form-control  cyf-inpput removeData" rows="" cols="" style="height: 100px;"></textarea>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="add_btn">保存</button>
					</div>
				</div>
			</div>
		</div>
		<!-- Modal 修改-->
		<div class="modal fade" id="EdCollegeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="">编辑学院</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="form_eidt">
							<div class="form-group">
								<label class="col-sm-3 control-label">学院编号</label>
								<div class="col-sm-7">
									<input type="text" id="edit_sch_id" name="edit_sch_id" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学院名称</label>
								<div class="col-sm-7">
									<input type="text" id="edit_sch_name" name="edit_sch_name" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">办公地点</label>
								<div class="col-sm-7">
									<input type="text" id="edit_sch_office" name="edit_sch_office" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">院长</label>
								<select class="form-control poiu" id="edit_tea_boss" name="edit_tea_boss" style="width: 300px">
									<option value="0">请选择</option>
									<volist name="tea_sel_add" id="vo">
										<option value="{$vo.tea_id}">{$vo.tea_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3  control-label " style="margin-top: 30px;">简介: </label>
								<div class="col-sm-7">
									<textarea id="edit_sch_intro" name="edit_sch_intro" class="form-control  cyf-inpput" rows="" cols="" style="height: 100px;"></textarea>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="editBtn">保存</button>
					</div>
				</div>
			</div>
		</div>
		<include file="Layout:ins_js" />
		<script type="text/javascript">
            //自检
            check_index();

			$(document).ready(function() {
				sTable = $('.dataTables-example').DataTable({
					"sAjaxSource": "__URL__/college_manage_ShowDatatables",
					"bAutoWidth": false,
					//                    "bLengthChange": false,
                    "oLanguage": {
                        "sLengthMenu": "每页 _MENU_ ",
                        "sProcessing": "处理中...",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    },
					"aoColumns": [{
						'data': 'sch_id',
						"sClass": "hidden"
					}, {
						'data': 'sch_name',
					}, {
						'data': 'sch_office',
					}, {
						'data': 'tea_name',
					}, {
						'data': null,
						orderable: false,
						render: function(data, type, row, meta) {
							return '<a type="button" class="btn btn-success" onclick=editParam(this)>编辑</a> <a type="button" class="btn btn-danger" onclick=delParam(' + row.sch_id + ')>删除</a>';
						}
					}]
				});
			});
			//新增
            $('#addBtn').on('click', function() {
                $('.wrapper').removeClass('animated');
                $('#AdCollegeModal').modal();
            });
            $('#add_btn').on('click', function() {
                var formData = $('#form_add').serializeArray();
                var postData = {};

                $(formData).each(function(i) {
                    postData[this.name] = this.value;
                });

                sil_loading();
                $.ajax({
                    type: "post",
                    url: "__URL__/add_college",
                    async: true,
                    data: postData,
                    dataType: 'json',
                    success: function(p) {
                        if(p.state == true) {
                            toastr.success(p.info);
                            $('.removeData').val('');
                             $('#AdCollegeModal').modal('hide');
                             sTable.ajax.reload();
                        } else {
                            toastr.error(p.info);
                            // $('#add_brands_name').val('');
                        }
                        sil_reloading();
                    }
                });

            });
			function editParam(obj) {
				var Obj = $(obj).parent().parent();
				var rowdata = sTable.row(Obj).data();
				$('#edit_sch_id').val(rowdata.sch_id);
				$('#edit_sch_name').val(rowdata.sch_name);
				$('#edit_sch_office').val(rowdata.sch_office);
                $('#edit_sch_intro').val(rowdata.sch_intro);
                $('#edit_tea_boss').val(rowdata.tea_id);
				$('.wrapper').removeClass('animated');
				$('#EdCollegeModal').modal();
			}
			$('#editBtn').on('click', function() {
                var formData = $('#form_eidt').serializeArray();
                var postData = {};

                $(formData).each(function(i) {
                    postData[this.name] = this.value;
                });
				sil_loading();
				$.ajax({
					type: "post",
					url: "__URL__/edit_college",
					async: true,
                    data: postData,
					dataType: 'json',
					success: function(n) {
						if(n.state == true) {
							toastr.success(n.info);
							$('.removeData').val('');
							$('#EdCollegeModal').modal('hide');
                            sTable.ajax.reload();
						} else {
							toastr.error(n.info);
						}
						sil_reloading();
					}
				})
			});
			//删除
			function delParam(sch_id) {
				swal({
					title: '注意！',
					text: "是否删除",
					type: 'warning',
					showCancelButton: true, //显示取消按钮
					confirmButtonColor: '#3085d6', //确认按钮的颜色
					cancelButtonColor: '#d33', //取消按钮的颜色
					confirmButtonText: '确定', //确认按钮上面的字
					cancelButtonText: '取消', //取消按钮上的字 
				}).then(function(isConfirm) { //点击确认之后运行的方法
					if(isConfirm) {
						$.ajax({
							type: "post",
							url: "__URL__/delete_college",
							async: true,
							data: {
                                delete_sch_id: sch_id
							},
							dataType: 'json',
							success: function(c) {
								if(c.state == true) {
									toastr.success(c.info);
									sTable.ajax.reload();
								} else {
									toastr.error(c.info);
								}
							}
						})
					}
				})
			}
		</script>
	</body>

</html>